/*
 * LineStyle.java
 * 
 * Created by demory on Apr 1, 2009, 7:52:41 AM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.network;

import java.awt.Color;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author demory
 */
public class LineStyle implements Comparable<LineStyle>, LineStyleInfo {

  private int id_;
  private String name_;

  private List<SubStyle> substyles_;

  public enum Preset {
    DEFAULT(-1);
    
    private int id_;
    
    Preset(int id) {
      id_ = id;
    }

    public int getID() {
      return id_;
    }

  }

  public LineStyle() {
    substyles_ = new LinkedList<SubStyle>();
    name_ = "Unnamed Style";
  }

  public LineStyle(int id, String name) {
    substyles_ = new LinkedList<SubStyle>();
    id_ = id;
    name_ = name;
  }

  public LineStyle(Preset preset) {
    this();
    id_ = preset.id_;
    switch(preset) {
      case DEFAULT:
        addStyle(new SubStyle(10, Color.BLACK));
        break;
    }
  }

  public LineStyle getCopy() {
    LineStyle copy = new LineStyle(0, "Copy of "+name_);

    for(SubStyle ss : substyles_)
      copy.addStyle(new SubStyle(ss.getWidth(), ss.getColor()));

    return copy;
  }

  public int getID() {
    return id_;
  }

  public void setID(int id) {
    id_ = id;
  }

  public String getStyleName() {
    return name_;
  }

  public void setStyleName(String name) {
    name_ = name;
  }

  public List<SubStyle> getSubStyles() {
    return substyles_;
  }

  public void setSubStyles(List<SubStyle> substyles) {
    substyles_ = substyles;
  }

  public void addStyle(SubStyle sstyle) {
    substyles_.add(sstyle);
  }

  public int getWidth() {
    int max = 0;
    for(SubStyle style : substyles_) max = Math.max(max, style.getWidth());
    return max;
  }

  public SubStyle getHighlight() {
    return new SubStyle(getWidth()+4, Color.yellow);
  }

  private String compareStr() {
    return name_ + "_" + id_;
  }

  public int compareTo(LineStyle o) {
    return compareStr().compareTo(o.compareStr());
  }

}
